package com.yang.booking.controller;

import com.yang.booking.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.Map;

@RestController
public class StaffController {

    @Autowired
    private StaffService staffService;

    @PostMapping("/provider/staff/insertStaff")
    public Map<String, Object> insertStaff(@RequestParam(name = "storeId") String storeId,
                                            @RequestParam(name = "name") String name,
                                            @RequestParam(name = "position") String position,
                                            @RequestParam(name = "level") String level,
                                           @RequestParam(name = "employment") String employment,
                                           @RequestParam(name = "good") String good,
                                           @RequestParam(name = "introduce") String introduce,
                                           @RequestParam(name = "appSituation") String appSituation,
                                           @RequestParam(name = "onlineShopOrder") String onlineShopOrder,
                                           @RequestParam(name = "schedulingMethod") String schedulingMethod

    ){
        return staffService.insertStaff(storeId, name, position, Integer.parseInt(level), employment, good, introduce, Integer.parseInt(appSituation),
                Integer.parseInt(onlineShopOrder), Integer.parseInt(schedulingMethod));
    }

    @PostMapping("/provider/staff/queryStaff")
    public Map<String, Object> queryStaff(@RequestParam(name = "storeId") String storeId,
                                                    @RequestParam(name = "nameOrNo") String nameOrNo,
                                                    @RequestParam(name = "level") String level,
                                                    @RequestParam(name = "appSituation") String appSituation,
                                                    @RequestParam(name = "onlineShopOrder") String onlineShopOrder,
                                                    @RequestParam(name = "pageSize") String pageSize,
                                                    @RequestParam(name = "pageNo") String pageNo
    ){
        return staffService.queryStaff(storeId, nameOrNo, level, appSituation, onlineShopOrder, pageSize, pageNo);
    }

    @PostMapping("/provider/staff/queryStaffScheduling")
    public Map<String, Object> queryStaffScheduling(@RequestParam(name = "storeId") String storeId,
                                        @RequestParam(name = "nameOrNo") String nameOrNo,
                                        @RequestParam(name = "level") String level,
                                        @RequestParam(name = "pageSize") String pageSize,
                                        @RequestParam(name = "pageNo") String pageNo
    ){
        return staffService.queryStaffScheduling(storeId, nameOrNo, level, pageSize, pageNo);
    }

    @PostMapping("/provider/staff/updateStaffAppSituation")
    public Map<String, Object> updateStaffAppSituation(@RequestParam(name = "staffIdList") String staffIdList,
                                               @RequestParam(name = "appSituation") String appSituation
    ){
        return staffService.updateStaffAppSituation(staffIdList, appSituation);
    }

    @PostMapping("/provider/staff/updateStaffInfo")
    public Map<String, Object> updateStaffInfo(@RequestParam(name = "staffId") String staffId,
                                               @RequestParam(name = "name") String name,
                                               @RequestParam(name = "employment") String employment,
                                               @RequestParam(name = "good") String good,
                                               @RequestParam(name = "introduce") String introduce
    ){
        return staffService.updateStaffInfo(staffId, name, employment, good, introduce);
    }

    @PostMapping("/provider/staff/insertStaffSchedling")
    public Map<String, Object> insertStaffSchedling(@RequestParam(name = "storeId") String storeId,
                                                    @RequestParam(name = "staffIdList") String staffIdList,
                                                    @RequestParam(name = "schedlingMothed") String schedlingMothed,
                                                    @RequestParam(name = "frequencyId") String frequencyId,
                                                    @RequestParam(name = "biweeklyList") String biweeklyList
    ){
        return staffService.insertStaffSchedling(storeId, staffIdList, schedlingMothed, frequencyId, biweeklyList);
    }

    @PostMapping("/provider/staff/queryStaffBoard")
    public Map<String, Object> queryStaffBoard(@RequestParam(name = "storeId") String storeId,
                                                    @RequestParam(name = "arrivalDate") String arrivalDate
    ) throws ParseException {
        return staffService.queryStaffBoard(storeId, arrivalDate);
    }

    @PostMapping("/provider/staff/queryItemStaff")
    public Map<String, Object> queryItemStaff(@RequestParam(name = "storeId") String storeId,
                                              @RequestParam(name = "itemId") String itemId,
                                              @RequestParam(name = "nowDate") String nowDate
    ) throws ParseException {
        return staffService.queryItemStaff(storeId, itemId, nowDate);
    }

    @PostMapping("/provider/staff/testTime")
    public Map<String, Object> testTime(@RequestParam(name = "staffId") String staffId,
                                                    @RequestParam(name = "arrivalDate") String arrivalDate,
                                                    @RequestParam(name = "time") String time
    ){
        return staffService.testTime(staffId, arrivalDate, time);
    }

    @PostMapping("/provider/staff/queryBookableNumber")
    public Integer ookableNumber(@RequestParam(name = "storeId") String storeId,
                             @RequestParam(name = "arrivalDate") String arrivalDate
    ) throws ParseException {
        return staffService.queryBookableNumber(storeId, arrivalDate);
    }

    @PostMapping("/provider/staff/queryBookableNumberAsync")
    public Integer ookableNumberAsync(@RequestParam(name = "storeId") String storeId,
                                 @RequestParam(name = "arrivalDate") String arrivalDate
    ) throws ParseException, InterruptedException {
        return staffService.queryBookableNumberAsync(storeId, arrivalDate);
    }

    @PostMapping("/provider/staff/queryStaffBoardNew")
    public Map<String, Object> queryStaffBoardNew(@RequestParam(name = "storeId") String storeId,
                                               @RequestParam(name = "arrivalDate") String arrivalDate
    ) throws ParseException {
        return staffService.queryStaffBoardNew(storeId, arrivalDate);
    }

    @PostMapping("/provider/staff/queryStaffBoardAsync")
    public Map<String, Object> queryStaffBoardAsync(@RequestParam(name = "storeId") String storeId,
                                                  @RequestParam(name = "arrivalDate") String arrivalDate) throws InterruptedException {
        return staffService.queryStaffBoardAsync(storeId, arrivalDate);
    }

    @PostMapping("/provider/staff/queryStaffBoardAsyncNoPool")
    public Map<String, Object> queryStaffBoardAsyncNoPool(@RequestParam(name = "storeId") String storeId,
                                                    @RequestParam(name = "arrivalDate") String arrivalDate) throws InterruptedException{
        return staffService.queryStaffBoardAsyncNoPool(storeId, arrivalDate);
    }

    @PostMapping("/provider/staff/queryStaffBoardThread")
    public Map<String, Object> queryStaffBoardThread(@RequestParam(name = "storeId") String storeId,
                                                          @RequestParam(name = "arrivalDate") String arrivalDate) throws InterruptedException{
        return staffService.queryStaffBoardThread(storeId, arrivalDate);
    }

    @PostMapping("/provider/staff/queryStaffBoardSpringAsync")
    public Map<String, Object> queryStaffBoardSpringAsync(@RequestParam(name = "storeId") String storeId,
                                                     @RequestParam(name = "arrivalDate") String arrivalDate) throws InterruptedException{
        return staffService.queryStaffBoardSpringAsync(storeId, arrivalDate);
    }
}
